OPC Studio User's Guide and Reference
Examples - OPC XML-DA - Browse for leaves

.NET

// This example shows how to obtain all leaves under the "Simulation" branch of the address space. For each leaf, it displays 
// the ItemID of the node.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.AddressSpace;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess.Xml
{
    class BrowseLeaves
    {
        public static void Main1Xml()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();
            DANodeElementCollection leafElements;
            try
            {
                ServerDescriptor serverDescriptor = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
                leafElements = client.BrowseLeaves(serverDescriptor, "Static/Analog Types");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            foreach (DANodeElement leafElement in leafElements)
                Console.WriteLine($"LeafElements(\"{leafElement.Name}\").ItemId: {leafElement.ItemId}");
        }


        // Example output:
        //
        //LeafElements("Int").ItemId: Static/Analog Types/Int
        //LeafElements("Double").ItemId: Static/Analog Types/Double
        //LeafElements("Int[]").ItemId: Static/Analog Types/Int[]
        //LeafElements("Double[]").ItemId: Static/Analog Types/Double[]
    }
}
' This example shows how to obtain all leaves under the "Simulation" branch of the address space. For each leaf, it displays 
' the ItemID of the node.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports OpcLabs.EasyOpc
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.AddressSpace
Imports OpcLabs.EasyOpc.OperationModel

Namespace DataAccess.Xml
    Partial Friend Class BrowseLeaves
        Shared Sub Main1Xml()
            Dim client = New EasyDAClient()

            Dim leafElements As DANodeElementCollection
            Try
                Dim serverDescriptor As ServerDescriptor = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
                leafElements = client.BrowseLeaves(serverDescriptor, "Static/Analog Types")
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            For Each leafElement In leafElements
                Console.WriteLine($"LeafElements(""{leafElement.Name}"").ItemId: {leafElement.ItemId}")
            Next leafElement

        End Sub

        ' Example output
        '
        'LeafElements("Int").ItemId: Static/Analog Types/Int
        'LeafElements("Double").ItemId: Static/Analog Types/Double
        'LeafElements("Int[]").ItemId: Static/Analog Types/Int[]
        'LeafElements("Double[]").ItemId: Static/Analog Types/Double[]

    End Class
End Namespace

Python

# This example shows how to obtain all leaves under the "Simulation" branch of the address space. For each leaf, it displays 
# the ItemID of the node.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.DataAccess.AddressSpace import *
from OpcLabs.EasyOpc.OperationModel import *

# Instantiate the client object.
client = EasyDAClient()

try:
    leafElements = IEasyDAClientExtension.BrowseLeaves(client, ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'), DANodeDescriptor('Static/Analog Types'))
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message, sep='')
    exit()

for leafElement in leafElements:
    print('LeafElements("', leafElement.Name, '").ItemId: ', leafElement.ItemId, sep='')

# Example output:
#
#LeafElements("Int").ItemId: Static/Analog Types/Int
#LeafElements("Double").ItemId: Static/Analog Types/Double
#LeafElements("Int[]").ItemId: Static/Analog Types/Int[]
#LeafElements("Double[]").ItemId: Static/Analog Types/Double[]

 

QuickOPC supports OPC XML-DA also on Linux and macOS.
See Also

Examples - Client OPC Data Access

Examples - Client OPC Unified Architecture

Concepts